<%+cbi/valueheader%>
<div class="cbi-value-field" id="switch_dashboard_<%=self.option%>">
	<%:Collecting data...%>
</div>

<script type="text/javascript">//<![CDATA[
	var btn_type_<%=self.option%> = "<%=self.option%>";
	var switch_dashboard_<%=self.option%> = document.getElementById('switch_dashboard_<%=self.option%>');
	XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "dashboard_type")%>', null, function(x, status) {
      	if ( x && x.status == 200 ) {
			if ( btn_type_<%=self.option%> == "Dashboard" ) {
				if ( status.dashboard_type == "Meta" ) {
					switch_dashboard_<%=self.option%>.innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Switch To Official Version%>" onclick="return switch_dashboard(this, btn_type_<%=self.option%>, \'Official\')"/>';
				}
				else {
					switch_dashboard_<%=self.option%>.innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Switch To Meta Version%>" onclick="return switch_dashboard(this, btn_type_<%=self.option%>, \'Meta\')"/>';
				}
			}
			if ( btn_type_<%=self.option%> == "Yacd" ) {
				if ( status.yacd_type == "Meta" ) {
					switch_dashboard_<%=self.option%>.innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Switch To Official Version%>" onclick="return switch_dashboard(this, btn_type_<%=self.option%>, \'Official\')"/>';
				}
				else {
					switch_dashboard_<%=self.option%>.innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Switch To Meta Version%>" onclick="return switch_dashboard(this, btn_type_<%=self.option%>, \'Meta\')"/>';
				}
			}
			if ( btn_type_<%=self.option%> == "Metacubexd" ) {
				switch_dashboard_<%=self.option%>.innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Update Metacubexd Version%>" onclick="return switch_dashboard(this, btn_type_<%=self.option%>, \'Official\')"/>';
			}
      if ( btn_type_<%=self.option%> == "Zashboard" ) {
				switch_dashboard_<%=self.option%>.innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Update Zashboard Version%>" onclick="return switch_dashboard(this, btn_type_<%=self.option%>, \'Official\')"/>';
			}
        }
	});
    
	function switch_dashboard(btn, name, type)
	{
		btn.disabled = true;
		btn.value = '<%:Downloading File...%>';
		XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "switch_dashboard")%>', {name: name, type : type}, function(x, status) {
			if ( x && x.status == 200 ) {
				if ( status.download_state == "1" ) {
					if ( type == "Meta" ) {
						if ( name == "Dashboard" ) {
							document.getElementById("switch_dashboard_"+name).innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Switch Successful%> - <%:Switch To Official Version%>" onclick="return switch_dashboard(this, \'Dashboard\', \'Official\')"/>';
						}
						else
						{
							document.getElementById("switch_dashboard_"+name).innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Switch Successful%> - <%:Switch To Official Version%>" onclick="return switch_dashboard(this, \'Yacd\', \'Official\')"/>';
						}
					}
					else {
						if ( name == "Dashboard" ) {
							document.getElementById("switch_dashboard_"+name).innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Switch Successful%> - <%:Switch To Meta Version%>" onclick="return switch_dashboard(this, \'Dashboard\', \'Meta\')"/>';
						}
						else if ( name == "Yacd" ) 
						{
							document.getElementById("switch_dashboard_"+name).innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Switch Successful%> - <%:Switch To Meta Version%>" onclick="return switch_dashboard(this, \'Yacd\', \'Meta\')"/>';
						}
						else if ( name == "Metacubexd" ) {
							document.getElementById("switch_dashboard_"+name).innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Update Successful%> - <%:Update Metacubexd Version%>" onclick="return switch_dashboard(this, \'Metacubexd\', \'Official\')"/>';
						} else {
							document.getElementById("switch_dashboard_"+name).innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Update Successful%> - <%:Update Zashboard Version%>" onclick="return switch_dashboard(this, \'Zashboard\', \'Official\')"/>';
            }
					}
				}
				else if ( status.download_state == "2" ) {
					btn.value = '<%:Unzip Error%>';
				}
				else {
					if ( name == "Metacubexd" || name == "Zashboard" ) {
						btn.value = '<%:Update Failed%>';
					}
					else {
						btn.value = '<%:Switch Failed%>';
					}
				}
			}
		});
		btn.disabled = false;
		return false; 
	}

//]]></script>
      
<%+cbi/valuefooter%>